/*
 * Creation : 17/09/2013
 */
/**
 * 
 */
package com.japcatalog.util;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * Singleton class util to control de Hibernate SessionFactory.
 * 
 * @author Fernando Ariel Perelli
 * 
 */
public final class HibernateUtil {

	/** The session factory. */
	private SessionFactory sessionFactory;

	/** The hibernate util. */
	private static HibernateUtil hibernateUtil;

	/**
	 * Instantiates a new hibernate util.
	 */
	@SuppressWarnings("deprecation")
	private HibernateUtil() {
		// A SessionFactory is set up once for an application configures
		// settings from hibernate.cfg.xml
		this.sessionFactory = null;
		try {
			this.sessionFactory = new Configuration().configure().buildSessionFactory();
		} catch (HibernateException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * Gets the intance.
	 * 
	 * @return the intance
	 */
	public static HibernateUtil getIntance() {
		if (hibernateUtil == null) {
			hibernateUtil = new HibernateUtil();
		}
		return hibernateUtil;
	}

	/**
	 * Gets the session factory.
	 * 
	 * @return the session factory
	 */
	public SessionFactory getSessionFactory() {
		return this.sessionFactory;

	}
}
